<template>
{{#if ctrl.psSysPFPlugin}}
    {{> @macro/plugins/widget/widget-use.hbs appPlugin=ctrl.psSysPFPlugin}}
{{else}}
    {{#if (neq ctrl.portletType 'CONTAINER')}}
    <AppCol :layoutOpts="{{> @macro/common/layoutPos.hbs layout=ctrl.psLayout layoutPos=ctrl.psLayoutPos}}">
        <AppPortlet 
            name="{{ctrl.name}}"
            title="{{ctrl.title}}" 
            {{#if ctrl.titlePSLanguageRes}}
            titlePSLanguageRes="{{ctrl.titlePSLanguageRes.lanResTag}}"
            {{/if}}
            class="app-control-dashboard__parent control-content {{lowerCase ctrl.codeName}} {{#if item.psSysCss}}{{item.psSysCss.cssName}}{{/if}}" 
            width="{{#if ctrl.width}}{{ctrl.width}}px{{else}}100%{{/if}}"
            height="{{#if ctrl.height}}{{ctrl.height}}px{{else}}100%{{/if}}"            
            :isShowTitle="{{ctrl.showTitleBar}}" 
            :actions="store.actions" 
            :image="{imagePath:'{{ctrl.psSysImage.imagePath}}',cssClass: '{{ctrl.psSysImage.cssClass}}'}"  
            @component-action="(actionParam: IEvent<string>) => { handleComponentAction(controller, actionParam) }"
        >
            {{> @macro/widgets/portlet-detail/include-portlet.hbs type=ctrl.portletType item=ctrl}}
        </AppPortlet>
    </AppCol>
    {{else}}
    {{> @macro/widgets/portlet-detail/include-portlet.hbs type=ctrl.portletType item=ctrl}}            
    {{/if}}
{{/if}}
</template>
<script setup lang="ts">
// 基于template/src/widgets/\{{appEntities}}/\{{ctrls@PORTLET}}-portlet/\{{spinalCase ctrl.codeName}}-portlet.vue.hbs生成
{{> @macro/plugins/widget/widget-import.hbs ctrl=ctrl}}
import { model } from './{{spinalCase ctrl.parent.codeName}}-{{spinalCase ctrl.codeName}}-portlet-model';
import { AppPortlet, AppPortletContainer } from '@components/widgets/portlet';
import { AppCol } from '@/components/common/col';
import { 
    useNavParamsBind, 
    getCtrlClassNames, 
    useEventBind,
    handleCtrlInit,
    handleCtrlAction,
    handleCtrlDestroy,
{{#eq ctrl.portletType 'TOOLBAR'}}
    handleToolbarItemClick,
{{/eq}}
    handleComponentAction } from '@/hooks/use-ctrl';
{{#eq ctrl.portletType 'ACTIONBAR'}}
import { AppActionBar } from '@/components/common/action-bar';
{{/eq}}
{{#eq ctrl.portletType 'RAWITEM'}}
import { AppRaw } from '@/components/common/raw';
{{/eq}}
import { PortletActionType, PortletController, IPortletAbility, IPortletController, IPortletControllerParams, IPortletStore, IContext, ILoadingHelper, IParam, createUUID, IViewAbility, IViewCtx, IEvent } from '@/core';
{{> @macro/widgets/portlet-detail/import-item.hbs portlet=ctrl}}

// 输入参数
{{> @macro/widgets/ctrl/ctrl-props.hbs
    props="openView?: Function;
    newView?: Function;"
}}

{{> @macro/common/emit.hbs name="ctrl" actionType="PortletActionType" ability="IPortletAbility"}}

const controlID = 'id' + createUUID();  

const classNames = computed(() => {
    return getCtrlClassNames(model, props);
});

const params:IPortletControllerParams<PortletActionType, IPortletAbility> = {
    name: props.name,
    model,
    evt,
    controlID,
    openView: props.openView,
    newView: props.newView,    
    closeView: props.closeView,     
    pLoadingHelper: props.pLoadingHelper,
    pViewCtx: props.pViewCtx,
    handler: (data: IPortletStore) => { return reactive(data) }
};

{{> @macro/common/controller.hbs name="ctrl" IController="IPortletController" store="IPortletStore" ability="IPortletAbility" controller="PortletController"}}

const handleViewInit = (name: string, data: IViewAbility) => {
    controller.setSubAbility(name, data);
}
</script>